package com.medicalO2O.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;

/**
 * Created by Kevin on 2016/1/4.
 */
public class DoctorServiceUtils {
    public static LinkedList<String> weekList(String day){
        LinkedList<String> weekList =new LinkedList<String>();
        String[] weeks = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        Calendar cal = Calendar.getInstance();
        String[] dates = day.split("-"); //按照输入来的时间分割成年，月，日
        int y = Integer.parseInt(dates[0]);
        int m = Integer.parseInt(dates[1]) - 1;
        int d = Integer.parseInt(dates[2]);
        for (int i = 0; i < 7; i++) {
            cal.set(y, m, d + i);
            int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
            if (week_index < 0) {
                week_index = 0;
            }
            String week = weeks[week_index];
            weekList.add(week);
        }
        return weekList;
    }
    public static void processMap(Map<String, LinkedHashMap<String, Map<String, Map<String, Map<String, String>>>>> doctorMap) {
        //下面遍历到最底层
        for (Map.Entry<String, LinkedHashMap<String, Map<String, Map<String, Map<String, String>>>>> doctor : doctorMap.entrySet()) {
            for (Map.Entry<String, Map<String, Map<String, Map<String, String>>>> week : doctor.getValue().entrySet()) {
                for (Map.Entry<String, Map<String, Map<String, String>>> organization : week.getValue().entrySet()) {
                    for (Map.Entry<String, Map<String, String>> department : organization.getValue().entrySet()) {
                        String start_Time = "";
                        String end_Time = "";
                        LinkedHashMap<String, String> dateMap = new LinkedHashMap();//重新处理，这里判断是否时间承接
                        for (Map.Entry<String, String> date : department.getValue().entrySet()) {
                            String st = date.getKey();
                            String et = date.getValue();
                            if (!end_Time.equals(st)) {
                                start_Time = st;
                                end_Time = et;
                                dateMap.put(start_Time, end_Time);
                            } else {
                                end_Time = et;
                                dateMap.put(start_Time, end_Time);
                            }
                        }
                        //重新将处理后的时间存入
                        department.setValue(dateMap);
                    }
                }
            }
        }
    }
}
